<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Default_Model_Chitietdonhang extends ZF_DB{
    protected $_table_name = "chitietdonhang" ;
    
    protected $_mactdh;
    protected $_madonhang;
    protected $_masanpham;
    protected $_soluong;
    protected $_thue;
    protected $_thanhtien;
    
    public function getMaCTDH(){
        return $this->_mactdh;
    }
    public function setMaCTDH($mactdh){
        $this->_mactdh = $mactdh;
    }
    public function getMaDonHang(){
        return $this->_madonhang;
    }
    public function setMaDonHang($madonhang){
        $this->_madonhang = $madonhang;
    }
    public function getMaSanPham(){
        return $this->_masanpham;
    }
    public function setMaSanPham($masanpham){
       $this->_masanpham = $masanpham;
    }
    public function getSoLuong(){
        return $this->_masoluong;
    }
    public function setSoLuong($soluong){
        $this->_soluong = $soluong;
    }
    public function getThue(){
        return $this->_thue;
    }
    public function setThue($thue){
        $this->_thue = $thue;
    }
    public function getThanhTien(){
        return $this->_thanhtien;
    }
    public function setThanhTien($thanhtien){
        $this->_thanhtien = $thanhtien;
    }
    
    public function insert($madonhang, $masanpham, $soluong, $thue, $thanhtien){
        
        if($madonhang && $masanpham && $soluong && $thanhtien){             
                $data =  array(
                    'MaDonHang' =>$madonhang,
                    'MaSanPham'=>$masanpham,
                    'SoLuong'=>$soluong,
                    'Thue'=>$thue,
                    'ThanhTien'=>$thanhtien);
            if ($this->db->insert($this->_table_name,$data) == 1)
            {
                return $this->db->lastInsertId();
            }
	}
        return -1;
	
    }
   
    public function update($mactdh, $data){
        $where  = "MaCTDH = " . $mactdh;
	return $this->db->update(
                $this->_table_name,
                $data,$where);
    }
    
    public function getById($mactdh){
        if($mactdh)
	{
		$select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.MaCTDH = ?", $mactdh);
		
		$data = $this->db->fetchRow($select);
		if($data){
			$this->_mactdh = $data['MaCTDH'];
			$this->_madonhang = $data['MaDonHang'];
			$this->_masanpham = $data['MaSanPham'];
			$this->_soluong = $data['SoLuong'];
                        $this->_thue = $data['Thue'];       
                        $this->_thanhtien = $data['ThanhTien'];
                }
                return $data;
	}
	return -1;
    }
   
    public function listAll(){
        $select = $this->db->select()
                ->from($this->_table_name);
        $data = $this->db->fetchAll($select);
	return $data;
    }
    public function delete(){
            $this->getById($this->_id);
            $this->_active = 0;
            return $this->update();
    }
}
?>
